// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "Blueprint/UserWidget.h"
#include "Data/SaveInfoStruct.h"
#include "PlayerLevelWidget.generated.h"

UCLASS()
class MISCELLANEOUSPROJECT_API UPlayerLevelWidget : public UUserWidget
{
	GENERATED_BODY()
public:
	virtual void NativeOnInitialized() override;
	virtual void NativeConstruct() override;
public:
	void ConstructWidget(FSavedPlayerLevel PlayerLevel);
	UFUNCTION(BlueprintCallable, Category = MissionComponent)
	void ReceiveXP(float XPValue);
	UFUNCTION(BlueprintCallable, Category = MissionComponent)
	void ToggleProgressBar(bool Visible);
	UFUNCTION(BlueprintCallable, Category = MissionComponent)
	void UpdateXP();
	UFUNCTION(BlueprintCallable, Category = MissionComponent)
	void UpdatePlayerLevel(int32 Value);
	UFUNCTION(BlueprintCallable, Category = MissionComponent)
	float UpdateProgressBar();
	UFUNCTION(BlueprintCallable, Category = MissionComponent)
	void LoadVariables();
	UFUNCTION(BlueprintCallable, Category = MissionComponent)
	void SaveVariables();
public:
	UPROPERTY(meta = (BindWidget))
	class UBorder* DynamicBackground;
	UPROPERTY(meta = (BindWidget))
	class UProgressBar* LevelProgress;
	UPROPERTY(meta = (BindWidget))
	class UImage* LevelBackground;
	UPROPERTY(meta = (BindWidget))
	class UTextBlock* LevelText;
	UPROPERTY(EditAnywhere, BlueprintReadWrite, meta = (ExposeOnSpawn = "true"), Category = "Default")
	FSavedPlayerLevel PlayerLevel;

private:
	FTimerHandle UpdateXPTimerHandle;
	float XPFromMission;
	int32 CharacterLevel;
	float CurrentXP;
	float Percentage;
	float NeededXP;
	float TargetXP;
	bool IsVisible;
	float NeededXPMultiplier;
	float TotalXP;
	FTimerHandle RetriggerableHandle;
};
